/**
 * 用于解析中文词语评分结果<br>
 *
 * @module ChiVoxSDK/score
 * @author Don Li <kai.li@chivox.com>
 * @licence
 * Copyright (c) 2017 - 2020 ChiVox Inc. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

class Char {
    constructor(data) { this.data = data; }
    getChar() { return this.data.char; }
    getNormalize() { return this.data.normalize; }
}

class Phone {
    constructor(data) { this.data = data; }
    getChar() { return this.data.char; }
    getScore() { return this.data.score; }
}

class Word {
    constructor(data) { this.data = data; }
    getChar() { return this.data.char; }
    getDur() { return this.data.dur; }
    getStress() { return this.data.stress; }
    getScore() { return this.data.score; }
    getPhoneSize() {
        if (typeof this.data.phone == 'undefined')
            return 0;
        else
            return this.data.phone.length;
    }

    getPhone(i) { return new Phone(this.data.phone[i]); }
}

 /**
 * 英文词语评分结果类。
 */
class EnWordScore {
    constructor(data) { this.data = data; }

    getParams() { return this.data.params; }
    getRecordId() { return this.data.recordId; }
    getAudioUrl() { return this.data.audioUrl; }
    getRank() { return this.data.result.rank; }
    getOverall() { return this.data.result.overall; }
    getWordSize() { return this.data.result.details.length; }
    getWord(i) { return new Word(this.data.result.details[i]); }
    getCharSize() { return this.data.result.chars.length; }
    getChar(i) { return new Char(this.data.result.chars[i]); }

    hasError() {
        return
            (
             typeof this.data.result == 'undefined' ||
             typeof this.data.result.err != 'undefined' ||
             typeof this.data.result.error != 'undefined' ||
             typeof this.data.result.errID != 'undefined'
            );
    }
    getErrorCode() {
        if (typeof this.data.result != 'undefined' && typeof this.data.result.errID != 'undefined')
            return this.data.result.errID;
        else if (typeof this.data.result.error != 'undefined')
            return this.data.result.error;
    }
}

export default EnWordScore
